//
//  DetailJiuDianViewController.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/21.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "DetailJiuDianViewController.h"
#import "HBHBannerViewController.h"

#import "scrollVCell.h"
#import "JiuDianCell.h"
#import "HBHMainIconCell.h"
#import "JiuDianSecondCell.h"
#import "JIuDianThirdCell.h"
#import "MianPingLunCell.h"
#import "YouHuiQuanCell.h"
#import "HotelDetailCell.h"
#import "HotelRecommendCell.h"
#import "HBHWebViewCell.h"

#import "ChooseBtnFindView.h"
#import "successView.h"
#import "HBHChouseTypeView.h"
#import "RWBChouseTimeView.h"
@interface DetailJiuDianViewController ()<HWDNavHeadViewDelegate,UITableViewDelegate,UITableViewDataSource,UIWebViewDelegate,CLLocationManagerDelegate>{
    CLLocationManager *locationmanager;//定位服务
    NSString *strlatitude;//经度
    NSString *strlongitude;//纬度
}

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) UIButton *collectBtn;//
@property (nonatomic, strong) ChooseBtnFindView *chooseBtnV;
@property (nonatomic, strong) UIView *headerView;//第二区头
@property (nonatomic, strong) BaseMBView *baseBgView;
@property (nonatomic, strong) successView *successV;//成功的展示
@property (nonatomic) CGFloat webH;
@property (nonatomic) CGFloat webH1;
@property (nonatomic, strong) UIWebView *web;
@property (nonatomic, strong) UIWebView *web1;
/*
    0:详情介绍 1:商家推荐 2:用户评论
 */
@property (nonatomic, assign) NSInteger TypeDetailNUmber;
@property (nonatomic, retain) NSDictionary *detail;
@property (nonatomic) BOOL isCollecting;

@end

@implementation DetailJiuDianViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.hidden = YES;
    
    [self creatView];
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    [self getDetail];
    
    strlatitude = @"0";
    
    strlongitude = @"0";
    
    [self getLocation];
}

-(void)creatView
{
    _isCollecting = NO;
    [self.view addSubview:self.table];
    [self addBtn];
}

-(void)addBtn//添加返回按钮
{
    //收藏按钮
    UIButton *button = [TomamaUI createButton:0 Frame:CGRectMake(0, 20, 40*screenW_6, 44) targ:self sel:@selector(backButton) titleColor:[UIColor whiteColor] font:nil title:nil image:@"back" backGroundImage:nil];

    [self.view addSubview:button];
    
    
    //收藏按钮
    UIButton *rightButton = [TomamaUI createButton:0 Frame:CGRectMake(SCREENW - 85*screenW_6, 20, 60*screenW_6, 44) targ:self sel:@selector(onTapRightBarButton) titleColor:nil font:nil title:nil image:nil backGroundImage:nil];
    [self.view addSubview:rightButton];
    
    _collectBtn = [TomamaUI createButton:0 Frame:CGRectMake(0, 0, 20*screenW_6, 44) targ:self sel:@selector(onTapRightBarButton) titleColor:nil font:nil title:nil image:@"fav" backGroundImage:nil];
    [rightButton addSubview:_collectBtn];
    
    UIButton *collection = [TomamaUI createButton:0 Frame:CGRectMake(20*screenW_6, 0, 50*screenW_6, 44) targ:self sel:@selector(onTapRightBarButton) titleColor:TextRed font:nil title:@"收藏" image:nil backGroundImage:nil];
    [rightButton addSubview:collection];
}

- (void)backButton
{
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

-(UIWebView *)web
{
    if (!_web) {
        _web = [[UIWebView alloc]init];
        _web.delegate = self;
    }
    return _web;
}

-(UIWebView *)web1
{
    if (!_web1) {
        _web1 = [[UIWebView alloc]init];
        _web1.delegate = self;
    }
    return _web1;
}

//Web加载完成
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    //计算webView的高
    CGRect frame = webView.frame;
    frame.size.width = SCREENW;
    frame.size.height = 1;
    webView.scrollView.scrollEnabled = NO;
    webView.frame = frame;
    frame.size.height = webView.scrollView.contentSize.height;
    webView.frame = frame;
    if (webView == _web) {
        _webH = frame.size.height;
    }else{
        _webH1 = frame.size.height;
    }
    [HudHelper hideHudToView:self.view];
    [_table reloadData];
}

-(UITableView *)table
{
    if (!_table) {
        _table = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, SCREENW, SCREENH + 20) style:UITableViewStyleGrouped];
        _table.backgroundColor = backColor;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
        _table.showsVerticalScrollIndicator = NO;
        _table.delegate = self;
        _table.dataSource = self;
        __weak typeof(self) weakSelf = self;
        _table.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [weakSelf getDetail];
        }];
    }
    return _table;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 40*screenW_6;
    }
    return 0.000001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.000001;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {//酒店详情
        return 3;
    }else if (section == 1)//优惠券
    {
        NSArray *arr = _detail[@"businessCouponBeanList"];
        return arr.count;
    }
    if (_TypeDetailNUmber == 0 || _TypeDetailNUmber == 1) {
        return 1;
    }
    if (_TypeDetailNUmber == 2) {
        return [NSArray arrayWithArray:_detail[@"businessCommentBeanList"]].count;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    __weak typeof(self) weakSelf = self;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {//轮播Cell
            scrollVCell *cell= [tableView dequeueReusableCellWithIdentifier:@"scrollVCell"];
            if (!cell) {
                cell = [[scrollVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"scrollVCell"];
            }
            
            NSMutableArray *businessBannerBeanList = [NSMutableArray new];
            for (NSDictionary *dic in _detail[@"businessBannerBeanList"]) {
                [businessBannerBeanList addObject:dic[@"image"]];
            }
            [cell loadCellWithData:businessBannerBeanList];
            return cell;
        }else if (indexPath.row == 1){//信息Cell
            JiuDianSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JiuDianSecondCell"];
            if (!cell) {
                cell = [[JiuDianSecondCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"JiuDianSecondCell"];
            }
            [cell loadCell:_detail[@"businessBean"]];
            cell.block = ^(NSInteger index){
                switch (index) {
                    case 0:
                        [weakSelf goToWeb];
                        break;
                    case 1:
                        [weakSelf addOrder];
                        break;
                    case 2:
                        [weakSelf callHotel];
                        break;
                    case 3:
                        [weakSelf nearBy];
                        break;
                    default:
                        break;
                }
            };
            return cell;
        }else//地址导航Cell
        {
            JIuDianThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JIuDianThirdCell"];
            if (!cell) {
                cell = [[JIuDianThirdCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"JIuDianThirdCell"];
            }
            [cell loadCell:_detail[@"businessBean"]];
            
            cell.blcok = ^(){
                [weakSelf toBMK];
            };
            
            return cell;
        }
    }else if(indexPath.section == 1){//优惠券
        YouHuiQuanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YouHuiQuanCell"];
        if (!cell) {
            cell = [[YouHuiQuanCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YouHuiQuanCell"];
        }
        [cell loadCellWithData:_detail[@"businessCouponBeanList"][indexPath.row]];
        
        cell.block = ^(NSString *couponId){
            [weakSelf receiveCouponsWithCouponId:couponId];
        };
        
        return cell;
    }else//评价 推荐 介绍
    {
        if (_TypeDetailNUmber == 0) {//详情介绍
            HBHWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HBHWebViewCell"];
            if (!cell) {
                cell = [[HBHWebViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HBHWebViewCell"];
            }
            [cell loadCellWithWeb:self.web];
            return cell;
        }else if (_TypeDetailNUmber == 1)//商家推荐
        {
            HBHWebViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HBHWebViewCell"];
            if (!cell) {
                cell = [[HBHWebViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HBHWebViewCell"];
            }
            [cell loadCellWithWeb:self.web1];
            return cell;
        }
        else//用户评论
        {
            MianPingLunCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MianPingLunCell"];
            if (!cell) {
                cell = [[MianPingLunCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MianPingLunCell"];
            }
            [cell loadCell:_detail[@"businessCommentBeanList"][indexPath.row]];
            return cell;
        }
    }
    return nil;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2) {//详情介绍 商家推荐 用户评价选择
        
        if (!_headerView) {
            _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 40*screenW_6)];
            _headerView.backgroundColor = [UIColor whiteColor];
            
            //选择按钮
            _chooseBtnV = [[ChooseBtnFindView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 40*screenW_6) TitleArr:@[@"详情介绍",@"商家推荐",@"用户评价"]];
            [_headerView addSubview:_chooseBtnV];
            __weak typeof(self)weakSelf = self;
            _chooseBtnV.chooseBtnBlock = ^(NSInteger tagNumber)
            { //按钮选择的回调
                weakSelf.TypeDetailNUmber = tagNumber;
                if (weakSelf.TypeDetailNUmber == 1 && weakSelf.web1.frame.size.height <= 1) {
                    [HudHelper showProgressHudWithMessage:@"" toView:weakSelf.view];
                    NSString *content1 = [NSString stringWithFormat:@"<head><style>img{max-width:%fpx ;height: auto !important}</style></head>%@",SCREENW - 10,weakSelf.detail[@"businessBean"][@"recommend"]];
                    [weakSelf.web1 loadHTMLString:content1 baseURL:nil];
                }
                [weakSelf.table reloadData];
            };
            [_headerView addSubview:[ToolViewVC addCellLineLab:CGRectMake(15, 39*screenW_6, SCREENW-30, 1*screenW_6)]];
        }
        return _headerView;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 180*screenW_6;
        }else if (indexPath.row == 1){
            return 100*screenW_6;
        }else if (indexPath.row == 2){
            return 80*screenW_6;
        }
    }else if (indexPath.section == 1){
        return 120*screenW_6;
    }else if (indexPath.section == 2 && _TypeDetailNUmber == 1){
//        NSString *detail = [NSString stringWithFormat:@"%@",_detail[@"businessBean"][@"recommend"]];
//        return [TomamaUI getStringHeightWith:detail andWeith:SCREENW - 50*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6] andLineSpacing:14*screenW_6] + 36*screenW_6;
        return _webH1;
    }else if (indexPath.section == 2 && _TypeDetailNUmber == 0) {
//        NSString *detail = [NSString stringWithFormat:@"%@",_detail[@"businessBean"][@"introduce"]];
        return _webH;
    }else if (indexPath.section == 2 && _TypeDetailNUmber == 2) {
        CGFloat h;
        h += [TomamaUI getStringHeightWith:_detail[@"businessCommentBeanList"][indexPath.row][@"comment"] andWeith:SCREENW - 80*screenW_6 andFont:[UIFont systemFontOfSize:15*screenW_6]];
        if ([NSArray arrayWithArray:_detail[@"businessCommentBeanList"][indexPath.row][@"imgList"]].count) {
            h += 72*screenW_6;
        }
        return 65*screenW_6 + h;
    }
    return 0;
}

//-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
//{

//    return tableView.estimatedRowHeight;
//}

-(void)addSeccessView//成功展示
{
    //蒙板
    __weak typeof(self)weakSelf = self;
    _baseBgView = [[BaseMBView alloc]initWithFrame:CGRectMake(0,0,SCREENW,SCREENH)];
    [_baseBgView showView:self];
    _successV = [[successView alloc]initWithFrame:CGRectMake(40*screenW_6, 160*screenW_6, SCREENW-80*screenW_6, 340*screenW_6)];
    [_baseBgView addSubview:_successV];
    _successV.cancleBlock = ^(){//取消
        [weakSelf.view endEditing:YES];
        [weakSelf.successV removeFromSuperview];
        [weakSelf.baseBgView removeFromSuperview];
    };
    _baseBgView.dissBlock = ^(){//点击空白
        [weakSelf.view endEditing:YES];
        [weakSelf.successV removeFromSuperview];
        [weakSelf.baseBgView removeFromSuperview];
    };
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    if (scrollView.contentOffset.y>150*screenW_6) {
//        _baseTopView.backgroundColor = greenColor;
//        _titlelab.textColor = [UIColor whiteColor];
//    }else
//    {
//        _titlelab.textColor = _baseTopView.backgroundColor = [UIColor clearColor];
//    }
}

#pragma mark - 
-(void)goToWeb
{
    HBJDWebViewController *vc = [HBJDWebViewController new];
    vc.url = _detail[@"businessBean"][@"website"];
    vc.naviTitle = _detail[@"businessBean"][@"name"];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)addOrder
{
    __weak typeof(self) weakSelf = self;
    RWBChouseTimeView *view = [[RWBChouseTimeView alloc]initWithComplete:^(NSDate *date) {
        [weakSelf addOrderRequestWithData:[TomamaUI dateTostiring:date andString:@"yyyy-MM-dd HH:mm:ss"]];
    }];
    [view showOnView:self.view];
}

-(void)callHotel
{
    if ([ToolViewVC isNotNullStr:_detail[@"businessBean"][@"telephone"]]) {
        UIAlertController*alertController = [UIAlertController alertControllerWithTitle:@"友情提示" message:@"确定拨打该联系电话" preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*_Nonnullaction) {
        }]];
        [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnullaction) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_detail[@"businessBean"][@"telephone"]]]];
        }]];
        [[TomamaUI getTopVC] presentViewController:alertController animated:YES completion:^{
        }];
    }else
    {
        [TomamaUI creatAlertWithTarget:[TomamaUI getTopVC] message:@"该联系电话不正确" timeInterval:2];
    }
}

-(void)nearBy
{
    
}

-(void)onTapRightBarButton
{
    if (!_isCollecting) {
        [self collection];
    }else{
        [TomamaUI creatAlertWithTarget:self message:@"已收藏该酒店" timeInterval:2];
    }
}

#pragma mark - request
-(void)getDetail
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/business/businessDetails" Dic:@{@"id":_hotelId,@"userId":[Storage getToken],@"longitude":[NSString stringWithFormat:@"%lf",_userLocation.location.coordinate.longitude],@"latitude":[NSString stringWithFormat:@"%lf",_userLocation.location.coordinate.latitude]} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HudHelper hideHudToView:self.view];
                if ([responseDic[@"success"] boolValue]) {
                    _detail = responseDic;
                    NSString *content = [NSString stringWithFormat:@"<head><style>img{max-width:%fpx ;height: auto !important}</style></head>%@",SCREENW - 10,_detail[@"businessBean"][@"introduce"]];
                    [self.web loadHTMLString:content baseURL:nil];
                    _isCollecting = [_detail[@"isCollection"] boolValue];
                    if (_isCollecting) {
                        [_collectBtn setImage:[UIImage imageNamed:@"fav_hover"] forState:UIControlStateNormal];
                    }
                    [_table reloadData];
                }else{
                    [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
                }
                if ([_table.mj_header isRefreshing]) {
                    [_table.mj_header endRefreshing];
                }
            });
        }];
    });
}

-(void)addOrderRequestWithData:(NSString *)data
{
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/business/addOrder" Dic:@{@"jdUser.id":[Storage getToken],@"jdBusiness.id":_hotelId,@"scheduledTime":data} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HudHelper hideHudToView:self.view];
                if ([responseDic[@"success"] boolValue]) {
                    [self addSeccessView];
                }else{
                    [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
                }
            });
        }];
    });
}

-(void)collection
{
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/user/addCollectionRecord" Dic:@{@"jdUser.id":[Storage getToken],@"jdBusiness.id":_hotelId} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HudHelper hideHudToView:self.view];
                if ([responseDic[@"success"] boolValue]) {
                    _isCollecting = YES;
                    [_collectBtn setImage:[UIImage imageNamed:@"fav_hover"] forState:UIControlStateNormal];
                    [TomamaUI creatAlertWithTarget:self message:@"收藏成功" timeInterval:2];
                }else{
                    [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
                }
            });
        }];
    });
}

-(void)receiveCouponsWithCouponId:(NSString *)couponId
{
    [HudHelper showProgressHudWithMessage:@"" toView:self.view];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/business/receiveCoupons" Dic:@{@"jdUser.id":[Storage getToken],@"business.id":_hotelId,@"businessCouponId":couponId} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HudHelper hideHudToView:self.view];
                if ([responseDic[@"success"] boolValue]) {
                    [TomamaUI creatAlertWithTarget:self message:@"领取成功" timeInterval:2];
                }else{
                    [TomamaUI creatAlertWithTarget:self message:responseDic[@"msg"] timeInterval:2];
                }
            });
        }];
    });
}

-(void)toBMK
{
    CLLocationCoordinate2D loc = CLLocationCoordinate2DMake([_detail[@"businessBean"][@"latitude"] floatValue], [_detail[@"businessBean"][@"longitude"] floatValue]);
    UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"选用导航地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *a1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *a2 = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        CLLocationCoordinate2D loc1 = CLLocationCoordinate2DMake([_detail[@"businessBean"][@"latitude"] floatValue] - 0.006, [_detail[@"businessBean"][@"longitude"] floatValue] - 0.0065);
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:loc1 addressDictionary:nil]];
        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                       launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
                                       MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
    }];
    
    UIAlertAction *a3 = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=%f,%f&mode=riding&src=%@&backScheme=HubeiHotel", loc.latitude, loc.longitude,_detail[@"businessBean"][@"name"]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSURL *url = [NSURL URLWithString:urlString];
            [[UIApplication sharedApplication] openURL:url];
        }else{
            [TomamaUI creatAlertWithTarget:self message:@"请安装百度地图" timeInterval:2];
        }

    }];
    
    UIAlertAction *a4 = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        CLLocationCoordinate2D loc1 = CLLocationCoordinate2DMake([_detail[@"businessBean"][@"latitude"] floatValue] - 0.006, [_detail[@"businessBean"][@"longitude"] floatValue] - 0.0065);
        
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
            NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=%@&slon=%@&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&m=0&t=0",strlatitude,strlongitude,@"我的位置",loc1.latitude,loc1.longitude,_detail[@"businessBean"][@"name"]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            NSURL *r = [NSURL URLWithString:urlString];
            
            [[UIApplication sharedApplication] openURL:r];
        }else{
            [TomamaUI creatAlertWithTarget:self message:@"请安装高德地图" timeInterval:2];
        }
        
    }];
    [ac addAction:a1];
    [ac addAction:a2];
    [ac addAction:a3];
    [ac addAction:a4];
    
    [self presentViewController:ac animated:YES completion:nil];
}

-(void)getLocation
{
    //判断定位功能是否打开
    if ([CLLocationManager locationServicesEnabled]) {
        locationmanager = [[CLLocationManager alloc]init];
        locationmanager.delegate = self;
        [locationmanager requestAlwaysAuthorization];
        [locationmanager requestWhenInUseAuthorization];
        //设置寻址精度
        locationmanager.desiredAccuracy = kCLLocationAccuracyBest;
        locationmanager.distanceFilter = 5.0;
        [locationmanager startUpdatingLocation];
    }
}

#pragma mark 定位成功后则执行此代理方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    [locationmanager stopUpdatingHeading];
    //旧址
    CLLocation *currentLocation = [locations lastObject];
    
    //打印当前的经度与纬度
    strlatitude = [NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude];
    strlongitude = [NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude];
//    NSLog(@"lat:%@ long:%@",strlatitude,strlongitude);
}

@end
